package com.example.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.annotation.Xuxin;
import com.example.base.DemoContext;
import com.example.mapper.StudentMapper;
import com.example.module.Student;
import com.example.utils.TransactionManagerUtil;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;


@Service("studentService")
public class StudentService extends ServiceImpl<StudentMapper,Student> {

    private final Logger log = LoggerFactory.getLogger(StudentService.class);

    @Resource
    private StudentMapper studentMapper;

    @Transactional
//    @Async("taskExecutorA")
    @Xuxin
    public void add(Student student) {


        studentMapper.insert(student);

//        int result = studentMapper.add(student);
        System.out.println(DemoContext.getToken());
        System.out.println(DemoContext.getPhone());
        TransactionManagerUtil.afterCommitTransaction(student, st -> log.error("学生信息= {}", st.toString()));
    }

    public void delete(Long id){
        studentMapper.deleteById(id);
    }
}
